<?php
class blogs_category_model extends CI_Model{
	function __construct(){
		parent::__construct();
		$this->_table = 'blogs_categories';		
	}
	//lay de quy
	function get_all( $parent_id = 0 , $sym = '' ){		
		$this->db->order_by('ordering');
		$this->db->where('parent_id',$parent_id);
		$result =  $this->db->get($this->_table)->result();
		foreach($result as $item){
			$item->frefix = $sym;
			$item->child = $this->get_all($item->id,$sym.'►');
		}
		return $result;
	}
	function get_all_parent(){
		$this->db->order_by('ordering',"ASC");
		return $this->db->get($this->_table)->result();	
	}
	/*function delete($id){
		$parent_id = parent::get($id)->parent_id;
		parent::delete($id);
		$this->db->where('parent_id',$id);//old
		$this->db->update($this->_table,array('parent_id'=>$parent_id));
	}*/
	function get($id){
		return $this->db->where("id",$id)->get($this->_table)->row();
	}
	function delete($id){
		$this->db->where("id",$id)->delete($this->_table);
	}
	function update($id,$data){
		$this->db->where("id",$id)->update($this->_table,$data);
	}
	function insert($data){
		$this->db->insert($this->_table,$data);	
	}
}
	